Skip to content

fix(amazonq): Replacing message bus with direct communication #5949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 14, 2025

Conversation

LokeshDogga13
Copy link
Contributor

@LokeshDogga13 LokeshDogga13 commented Aug 4, 2025

Optimize AmazonQ Plugin Memory Usage [DO NOT MERGE]

Problem

AmazonQ plugin memory usage has increased due to:

  1. We are relying on message bus for FLARE-to-UI communication
  2. Growing ConcurrentHashMap from handling STOP button clicks on IDE side

Solution

  • Replace message bus with direct callbacks: Implement direct communication from ChatCommunicationManager to UI components, reducing message bus overhead
  • Revert PR fix(amazonq): Stop button disappears after being clicked #5765: Remove IDE-side STOP button handling as it's no longer needed and causes memory bloat from ConcurrentHashMap growth

Changes

  • Added direct callback mechanism in ChatCommunicationManager
  • Updated AmazonQPanel to register callback instead of subscribing to message bus
  • Modified AmazonQLanguageClientImpl and ActionRegistrar to use direct communication
  • Maintained backward compatibility with message bus as fallback

Checklist

  • My code follows the code style of this project
  • I have added tests to cover my changes
  • A short description of the change has been added to the CHANGELOG if the change is customer-facing in the IDE.
  • I have added metrics for my changes (if required)

Before

image

After

image

system is idle from 21:00 to 6:00 in second image

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

@LokeshDogga13 LokeshDogga13 requested a review from a team as a code owner August 4, 2025 17:07
Copy link

github-actions bot commented Aug 4, 2025

Qodana Community for JVM

1 new problem were found

Inspection name Severity Problems
Unused symbol 🔶 Warning 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

@LokeshDogga13 LokeshDogga13 changed the title fix(amazonq): Replacing message bus with direct communication fix(amazonq): Replacing message bus with direct communication [DO NOT MERGE] Aug 4, 2025
@LokeshDogga13 LokeshDogga13 changed the title fix(amazonq): Replacing message bus with direct communication [DO NOT MERGE] fix(amazonq): Replacing message bus with direct communication Aug 4, 2025
@@ -134,6 +136,11 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
browser.complete(
Browser(this@AmazonQPanel, webUri, project).also { browserInstance ->
wrapper.setContent(browserInstance.component())

// Register direct callback instead of using message bus
ChatCommunicationManager.getInstance(project).setChatUpdateCallback { message ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably just associate the browser with the communication manager

Copy link
Contributor Author

@LokeshDogga13 LokeshDogga13 Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browser is not in shared package, and cannot import it. I am able to do it using Any, but not sure if it is a right way to do it.

try {
chatAsyncResultManager.createRequestId(partialResultToken)
chatAsyncResultManager.getResult(partialResultToken)
handleCancellation(tabId, browser)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this ok to delete

Copy link
Contributor Author

@LokeshDogga13 LokeshDogga13 Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this code is introduced when stop conversation needed to be handled on JB side. Now it is not required. So reverting this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also maintain records for partial results cause they are received separately and we mark them done when the result is completed, are we sure that line 599-600 can be deleted?

Copy link
Contributor

@samgst-amazon samgst-amazon Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws/amazon-q-eclipse@b944c77

I tried to mirror the cancellation logic here how it's handled in Eclipse. In the bug bash today removing this results in the original issue where:

  • Hitting stop button once stops the response, prints "you have stopped.." message, but stop button still shows
  • Hitting stop button second time prints"you have stopped.." again, stop button disappears

jk jk
I did not see that this behavior was regression and that the double clicking stop button issue is still present in prod rn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is executed only on stop button, why do we need to store partial results in this case ? Additionally now stop is being handled by FLARE. So we can revert the code. As mentioned in the description the changes in this PR 5765 can be reverted.

try {
chatAsyncResultManager.createRequestId(partialResultToken)
chatAsyncResultManager.getResult(partialResultToken)
handleCancellation(tabId, browser)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also maintain records for partial results cause they are received separately and we mark them done when the result is completed, are we sure that line 599-600 can be deleted?

@@ -40,7 +40,8 @@ class ActionRegistrar {
val params = SendToPromptParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU)
uiMessage = FlareUiMessage(command = SEND_TO_PROMPT, params = params)
}
AsyncChatUiListener.notifyPartialMessageUpdate(project, uiMessage)
ChatCommunicationManager.getInstance(project).notifyUi(uiMessage)
// AsyncChatUiListener.notifyPartialMessageUpdate(project, uiMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@LokeshDogga13 LokeshDogga13 merged commit ce3a4ed into main Aug 14, 2025
18 of 19 checks passed
@LokeshDogga13 LokeshDogga13 deleted the lodogga/memoryUsage branch August 14, 2025 05:31
rli added a commit that referenced this pull request Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants